<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:if test="admin.adminId==null"><s:text name="admin.add.title"/></s:if><s:else><s:text name="admin.edit.title"/></s:else></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
</head>
<body>
<div id="wrapper">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="admin.title"/></div>
	<div class="listtit"><p><span><strong><s:if test='orig =="input"'><s:text name="admin.add.title"/></s:if><s:elseif  test='orig =="editSelf"'><s:text name="admin.edit.self"/></s:elseif><s:else><s:text name="admin.edit.title"/></s:else></strong></span></p></div>
	<c:if test='${orig =="editSelf" }'>
	<div id="listoperate" class="listoperate whitebg blinks bbAFC4D3">
		<span class="space20"></span>
		<a href="#" class="current">个人信息修改</a>|
		<a href="#">密码修改</a>
	</div>
	</c:if>
	<div class="listadd">
		<s:form action="admin-save" id="admin-save">
		<s:hidden name="admin.adminId"/>
		<s:hidden name="orig" />
		<s:hidden name="pbno"/>
		<s:hidden name="pbMax"/>
		<s:hidden name="unitCode" id="unitCode"/>
		<table class="addgrid">
		<s:if test="admin.adminId==null">
			<tr>
				<th width='200'><s:text name="admin.loginName"/>:</th>
				<td> 
					<s:textfield name="admin.loginName" required="true" requiredposition="right" cssClass="txtin"/>
				<span id="point-loginName-Message" style="color: red;">*</span>
				
				</td>
			</tr>
		</s:if>
		<s:else>
			<tr>
				<th width='200'><s:text name="admin.loginName"/>:</th>
				<td>
				<s:property  value="admin.loginName"/>
				</td>
			</tr>
		</s:else>
			<tr>
				<th><s:text name="admin.realName"/>:</th>
				<td><s:textfield name="admin.realName" required="true" requiredposition="right" cssClass="txtin" onblur="checkRealName()"/>
				<span id="point-realName-Message" style="color: red;">*</span>
				</td>
			</tr>
			<tr>
				<th><s:text name="admin.nickName"/>:</th>
				<td><s:textfield name="admin.nickName" maxlength="18" id="nickName_input" required="true" requiredposition="right" cssClass="txtin" />
				<span id="point-nickName-Message" style="color: red;"></span>
				</td>
			</tr>
			<tr>
				<th><s:text name="admin.email"/>:</th>
				<td><s:textfield name="admin.email" cssClass="txtin"/>
					<span id="point-email-Message"></span>
				</td>
			</tr>
			<tr>
				<th><s:text name="admin.mobile"/>:</th>
				<td><s:textfield name="admin.mobile" cssClass="txtin" maxlength="11"/>
					<span id="point-mobile-Message"></span>
				</td>
			</tr>
			<tr>
				<th><s:text name="admin.telephone"/>:</th>
				<td><s:textfield name="admin.telephone" cssClass="txtin" maxlength="13" />
					<span id="point-telephone-Message"></span>
					<span id="point-telephone-Message2" style="color:#457d07">(电话格式例如:0571-888888888)</span>
				</td>
			</tr>
<c:if test='${orig =="edit" }'>
			<tr>
				<th><s:text name="admin.updateRealName"/>:</th>
				<td>
				<s:textfield name="admin.updateRealName" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="admin.createTime"/>:</th>
				<td><s:textfield name="admin.createTime" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="admin.updateLoginName"/>:</th>
				<td><s:textfield name="admin.updateLoginName" cssClass="txtin unable" readonly="true" /></td>
			</tr>
			<tr>
				<th><s:text name="admin.lastSuccessIp"/>:</th>
				<td><s:textfield name="admin.lastSuccessIp" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="admin.lastSuccessTime"/>:</th>
				<td><s:textfield name="admin.lastSuccessTime" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="admin.lastFailIp"/>:</th>
				<td><s:textfield name="admin.lastFailIp" cssClass="txtin unable" readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="admin.lastFailTime"/>:</th>
				<td><s:textfield name="admin.lastFailTime" cssClass="txtin unable"  readonly="true"/></td>
			</tr>
			<tr>
				<th><s:text name="admin.failNum"/>:</th>
				<td><s:textfield name="admin.failNum" cssClass="txtin unable" readonly="true"/></td>
			</tr>
	</c:if>
	<c:if test='${orig !="editSelf" }'>
			<tr>
				<th><s:text name="admin.cmsRole"/>: </th>
				<td>
					<s:select name="admin.role.roleId" id="roleID" list="roleLists" listKey="roleId" listValue="roleName" onblur="roleChange();" headerKey="0" headerValue="--" class="selectClass">
				</s:select>
				<span id="point-roleId-Message" style="color: red;">*</span>
				 </td>
			</tr>
			<tr>
				<th><s:text name="所属协会"/>: </th>
				<td>
					<s:textfield  name="admin.associatetor" id="unit" cssClass="txtin" readonly="true"/>&nbsp;<a id="asstorSelect">选择 </a>
				</td>
			</tr>
			<tr>
				<th><s:text name="area"/>: </th>
				<td>
					<c:if test='${orig =="edit" }'>
						<div class="area_alredy">
						<c:if test="${admin.area != null }">
							<span><s:property value="%{getSiteAreaValue(admin.area)}"/></span>
							<div>
								<s:select list="dicArea" cssClass="selectNor m01500" id="country" name="countryArea" headerKey="" headerValue="-----请选择-----" listKey="dictionaryKey" listValue="dictionaryValue"></s:select>
								<s:select list="#{}" cssClass="selectNor m01500" id="province" name="provinceArea" headerKey="" headerValue="--------请选择--------" listKey="dictionaryKey" listValue="dictionaryValue" ></s:select>
								<s:select list="#{}" cssClass="selectNor m01500" id="city" name="cityArea" headerKey="" headerValue="--------请选择--------" listKey="dictionaryKey" listValue="dictionaryValue"></s:select>	
							</div>
						</c:if>
						</div>
					</c:if>
					<c:if test='${orig !="edit" }'>
						<s:select list="dicArea" cssClass="selectNor m01500" id="country" name="countryArea" headerKey="" headerValue="-----请选择-----" listKey="dictionaryKey" listValue="dictionaryValue" ></s:select>
						<s:select list="#{}" cssClass="selectNor m01500" id="province" name="provinceArea" headerKey="" headerValue="--------请选择--------" listKey="dictionaryKey" listValue="dictionaryValue" ></s:select>
						<s:select list="#{}" cssClass="selectNor m01500" id="city" name="cityArea" headerKey="" headerValue="--------请选择--------" listKey="dictionaryKey" listValue="dictionaryValue"></s:select>
					</c:if>
				</td>
			</tr>
			<tr>
				<th><s:text name="admin.memo"/>:</th>
				<td>
				<s:textarea name="admin.memo" cssClass="memoclass" id="admin_memo" /></td>
			</tr>
</c:if>
			<tr>
				<th>&nbsp;</th>
				<td>
				<input type="button" value="<s:text name="save"/>" id="submit_input" class="btnlist2" onclick="formSubmit()"/>
				<s:reset value="%{getText('reset')}" cssClass="btnlist2"/>
				<input type="button" value="<s:text name='return'/>" class="btnlist2" onclick="history.back()">
				</td>
			</tr>
			</table>
			<table class="addgrid none">
			<c:if test='${orig =="editSelf" }'>
			
				<tr>
					<th><s:hidden name="selfInfo" id="selfInfo"/><s:text name="admin.passwd.old"/>: </th>
					<td><s:hidden name="paw" id="paw"/><s:password name="admin.passwd" id="admin.passwd" maxlength="18" cssClass="txtin" value=""></s:password>  </td>
				</tr>
				<tr>
					<th><s:text name="admin.passwd.new"/>: </th>
					<td><s:password name="admin.newPasswd" id="admin.newPasswd" maxlength="18" cssClass="txtin"></s:password>  </td>
				</tr>
				<tr>
					<th><s:text name="admin.passwd.again"/>: </th>
					<td><s:password name="admin.newPasswdAgain" id="admin.newPasswdAgain" maxlength="18" cssClass="txtin"></s:password>
						<span id="point-newPasswdAgain-Message"></span>
					  </td>
				</tr>
				<tr>
					<th>&nbsp;</th>
					<td><input type="button" value="<s:text name="save"/>" id="submit_input" class="btnlist2" onclick="formSubmit()"/></td>
			</tr>
			</c:if>
			
		</table>
		</s:form>
		
		
	</div>
</div>


<div id="lightbox_i" class="lightbox" >
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose_i" class="lightclose" /><strong>协会选择</strong></span></p></div>
	<div class="lightmain">
		<div class="lightmaintit">协会选择</div>
		<div class="ilghtmainbox" style="OVERFLOW-y:auto;OVERFLOW:scroll;overflow-x:auto;">
			<div id="authorSetDiv" >
				<label><s:text name="协会名称"/>: </label>
				<s:textfield  cssClass="txtsearch" id="fullName"/>
				<input type="button" value="<s:text name="query"/>" class="btnsearch" id="search_btn"/>
				<table class="listgridb" cellspacing="1" id="listbox_i">
				<tr><td></td></tr>
				</table>
			</div>
		</div>
		<div class="lightbtnbox">
			<input type="button" value="上一页" id="lastPb" class="btnlist2" />
			<input type="button" value="确认" id="lightsubmit_i" class="btnlist2" />
			<input type="button" value="返回" id="lightclosebtn_i" class="btnlist2" />
			<input type="button" value="下一页" id="nextPb" class="btnlist2" />
		</div>
	</div>
</div>

<!-- end -->
</body>
</html>
<script type="text/javascript" defer="defer">
var selfInfo = $("#selfInfo").val();
if(selfInfo == "selfInfo"){
	alert("信息修改成功");
}


$("#asstorSelect").click(function(){
	$("#fullName").val('');//置空搜索项
	$.ajax({	
		url:"${ctx}/system/showassociators-select.action?",
		type:"post",
		success:function(data){
			tableData(data);
		}
	});
	$$.shade("#asstorSelect","#lightclose_i,#lightsubmit_i,#lightclosebtn_i","#lightbox_i","700");
});
$("#nextPb").click(function(){
	var fullName = $("#fullName").val();
	if($("input[name=pbno]").val()==$("input[name=pbMax]").val()){
		alert("已经是最后一页！");
		return false;
	}
	$.ajax({	
		url:"${ctx}/system/showassociators-select.action?time="+new Date().getTime(),
		data:{"pb.pageNo":parseInt($("input[name=pbno]").val())+1,"fullName":fullName},
		dataType:"text",
		type:"post",
		success:function(data){
			tableData(data);
		}
	});
});
$("#lastPb").click(function(){
	var fullName = $("#fullName").val();
	if($("input[name=pbno]").val()==1){
		alert("已经是第一页！");
		return false;
	}
	$.ajax({	
		url:"${ctx}/system/showassociators-select.action?time="+new Date().getTime(),
		data:{"pb.pageNo":$("input[name=pbno]").val()-1,"fullName":fullName},
		dataType:"text",
		type:"post",
		success:function(data){
			tableData(data);
		}
	});
});

//搜索
$("#search_btn").click(function(){
	var fullName = $("#fullName").val();
	$.ajax({	
		url:"${ctx}/system/showassociators-select.action?time="+new Date().getTime(),
		data:{"pb.pageNo":1,"fullName":fullName},
		dataType:"text",
		type:"post",
		success:function(data){
			tableData(data);
		}
	});
	
});

function tableData(data){
		var str="<tbody>";
		var json = eval('('+data+')');
		$("input[name=pbno]").val(json.pageNo);
		if(parseInt(json.pageNo)==1){
			$("#lastPb").attr("disabled",true);
		}
		else{
			$("#lastPb").attr("disabled",false);
		}			
		$("input[name=pbMax]").val(json.pageMax);
		if(parseInt(json.pageNo)==parseInt(json.pageMax)){
			$("#nextPb").attr("disabled",true);
		}
		else{
			$("#nextPb").attr("disabled",false);
		}
		str+="<tr>";
		str+="<th>选择</th>";
		str+="<th>协会名称</th>";
		str+="<th>所属地区</th>";
		str+="<th>地址</th>";
		str+="</tr>";
		for(var i = 0 ; i<json.list.length ; i++){
			str+="<tr>";
			str+="<td><input type='radio' onclick='getUnit("+json.list[i].unitCode+")' name='selectAssocia' value="+json.list[i].unitCode+"></td>";
			str+="<td>"+json.list[i].fullName+"</td>";
			str+="<td>"+json.list[i].areaId+"</td>";
			str+="<td>"+json.list[i].address+"</td>";
			str+="</tr>";
		}
		str+="</tbody>";
		$("#listbox_i").html(str);
}

function getUnit(code){
	$("#unitCode").val(code);
}

 $("#lightsubmit_i").click(function(){
	var unitCode = $("#unitCode").val();
	$.post("${ctx}/system/showassociators-fullname.action?unitCode="+unitCode,function(data){
		$("#unit").val(data);
	});
}); 

var memo=document.getElementById("admin_memo");
if(memo!=undefined){
	if (window.navigator.userAgent.indexOf("MSIE")>=1) {
		memo.onpropertychange=memoChange;
	 } else{
		 memo.addEventListener("input", memoChange, false);
	 } 
}

var loginName_pass=false;

var realName_pass =true;
var email_pass    =true;
var mobile_pass   =true;
var telephone_pass=true;

	<s:if test="admin.adminId!=null"> 
		loginName_pass=true;
		
	</s:if>
	function formSubmit(){
		var tagText = $(".current").text();
		var adminName=$("input[name=admin.loginName]").val();
		if(adminName==''){
			$("#point-loginName-Message").html("请填写用户名");;
			return ;
		}
		var adminNick=$("input[name=admin.nickName]").val();
		
		if($("#roleID").val()==0){ 
			$("#point-roleId-Message").html("请选择角色");
			return;
		}else{
			$("#point-roleId-Message").html("");
		}
		var realName=$("input[name=admin.realName]").val();
		if(realName==""){
			$("#point-realName-Message").html("不能为空！");
			return false;
		}else{
			$("#point-realName-Message").html("");
		}
		var form0=$("#admin-save");
		<s:if test="admin.adminId==null">
			form0.submit();
			return false;
		</s:if>
		var adminId=$("input[name=admin.adminId]").val();
		var passwd=$("input[name=admin.passwd]").val();
		var passwdNew=$("input[name=admin.newPasswd]").val();
		var passwdNewAgaim=$("input[name=admin.newPasswdAgain]").val();
		if(tagText == '个人信息修改'){
			if(loginName_pass&&realName_pass&&email_pass&&mobile_pass&&telephone_pass){
				form0.submit();
				if($("#admin.passwd").val()=="" || $("#admin.passwd").val() == null){
					var paw = $("#password").val();
					$("#paw").val(paw);
				}
			}
		}else if(tagText =='密码修改'){
			if(passwd==''){
				alert("旧密码不能为空！");
				return false;
			}
			if(passwdNew==''){
				alert("新密码不能为空！");
				return false;
			}
			if(passwdNewAgaim!=passwdNew){
				alert("两次密码不相同！");
				return false;
			}
			var obj={"admin.passwd":passwd,"admin.newPasswd":passwdNew,"admin.newPasswdAgain":passwdNewAgaim,"admin.adminId":adminId};
			$.post("${ctx}/system/admin-pwdupdate.action",obj,function(data){
				if(data!=''){
					alert(data);
				/* 	if((loginName_pass==true)&&(realName_pass&&email_pass==true)&&(mobile_pass&&telephone_pass==true)){
						form0.submit();
					}
				}else{
					if((loginName_pass==true)&&(realName_pass&&email_pass==true)&&(mobile_pass&&telephone_pass==true)){
						form0.submit();
					} */
				}else{
					alert("修改密码失败！");
				}
			});
		}else{
			if(email_pass==true&&mobile_pass==true&&telephone_pass==true){
				form0.submit();
			}else{
				return false;
			}
			
		}
	
	}
	

	$$.addEvent("#admin-save_admin_loginName","blur",function(){
		var loginName=$('input[name=admin.loginName]').val();
		if(loginName==""){
			loginName_pass=false;
			$$.g("#point-loginName-Message").style.color = "#f00"; 
			$$.g("#point-loginName-Message").innerHTML = "请填写用户名";
		}else{
			if (!$$.username(loginName,3,18)){
				$$.g("#point-loginName-Message").style.color = "#f00"; 
				loginName_pass=false;
				$$.g("#point-loginName-Message").innerHTML = "用户名格式错误！用户名以字母开头，由3--18位的数字、字母、下划线组成";
			}else{
				var adminId=$('input[name=admin.adminId]').val();
				var obj={"admin.loginName":loginName,"admin.adminId":adminId};
				$.post("${ctx}/system/admin-checknameunique.action",obj,function(data){
					if(data=="unique"){
						loginName_pass=true;
						$$.g("#point-loginName-Message").style.color = "#0f0"; 
						$$.g("#point-loginName-Message").innerHTML = "用户名可用";
					}else if(data=="exist"){
						loginName_pass=false;
						$$.g("#point-loginName-Message").style.color = "#F00"; 
						$$.g("#point-loginName-Message").innerHTML = "用户名已经被占用，请重新输入";
					}
					}); 
			}
		}
	});
	
	//检测用户真实姓名
	function checkRealName(){
		var realName=$("input[name=admin.realName]").val();
		if(realName==""){
			$("#point-realName-Message").html("不能为空！");
		}else{
			$("#point-realName-Message").html("");
		}
	}
	
	function roleChange(){
		var roleId=$("#roleID").val();
		if(roleId=="0"){
			$("#point-roleId-Message").html("请选择角色");
		}else{
			$("#point-roleId-Message").html("");
		}
	}
	
	
	
	$$.addEvent("#admin-save_admin_email","blur",function(){
		var email=$("#admin-save_admin_email").val();
		if(email==""){
			$("#point-email-Message").html("");
			email_pass=true;
		}else{
			if(!$$.email(email)){
				$$.g("#point-email-Message").style.color="#F00";
				$$.g("#point-email-Message").innerHTML = "邮件格式错误";
				email_pass=false;
			}else{
				$$.g("#point-email-Message").style.color="#0f0";
				$$.g("#point-email-Message").innerHTML = "成功";
				email_pass=true;
			}
		}
	});
	
	$$.addEvent("#admin-save_admin_mobile","blur",function(){
		var mobile=$("#admin-save_admin_mobile").val();
		if(mobile==""){
			$("#point-mobile-Message").html("");
			mobile_pass=true;
		}else{
			if(!$$.mobile(mobile)){
				$$.g("#point-mobile-Message").style.color="#F00";
				$$.g("#point-mobile-Message").innerHTML = "手机格式错误";
				mobile_pass=false;
			}else{
				$$.g("#point-mobile-Message").style.color="#0f0";
				$$.g("#point-mobile-Message").innerHTML = "成功";
				mobile_pass=true;
			}
		}
	});

    
    $$.addEvent("#admin-save_admin_telephone","blur",function(){
    	var tel=$("#admin-save_admin_telephone").val();
    	if(tel==""){
    		$$.g("#point-telephone-Message").innerHTML = "";
    		telephone_pass=true;
    	}else{
    		var telephoneReg= /^\d{3}-\d{7}|\d{3}-\d{8}|\d{4}-\d{7}|\d{4}-\d{8}$/;
    		if(!telephoneReg.test(tel) ){
    			$$.g("#point-telephone-Message").style.color="#F00";
    			$$.g("#point-telephone-Message").innerHTML = "请输入正确的电话格式，例如:0571-888888888";
    			$$.g("#point-telephone-Message2").style.display="none"; 
    			telephone_pass=false;
    		}else{
    			$$.g("#point-telephone-Message").innerHTML = "";
    			$$.g("#point-telephone-Message").style.color="#0f0";
    			$$.g("#point-telephone-Message").innerHTML = "成功";
    			$$.g("#point-telephone-Message2").style.display="none"; 
    			telephone_pass=true;
    		}
    	}
	}); 
	function memoChange(){
		var maxLength=250;
		if(memo.value.length>maxLength){
			memo.value=memo.value.substring(0,maxLength);
		}
	}
	
	$("#country").change(function(){
		getProvince();
	});
	
	//获得二级区域
	function getProvince(){
		$("#province option").remove();
		$("#city option").remove();
		$("#city").append("<option value=''>-----请选择-----</option>");
		var parentKey = $("#country").val();
		if(parentKey == ""){
			$("#province").append("<option value=''>--------请选择--------</option>");
		}else{
			var obj = {"parentKey":parentKey};
			$.post("${ctx}/front/esp/espadmin-getcity.action", obj, function(data){
				var json = eval('('+data+')');
				var dicIds = json.dicIds.split("@");
				var dicKeys = json.dicKeys.split("@");
				var dicValues = json.dicValues.split("@");
				var str = "";
				str+="<option value=''>--------请选择--------</option>";
				for(var i = 0 ; i < dicIds.length ; i++){
					str+="<option value='"+dicKeys[i]+"'>"+dicValues[i]+"</option>";
				}
				$("#province").append(str);
			});
		}
	}
	
	$("#province").change(function(){
		getCity();
	});
	
	//获取三级区域
	function getCity(){
		$("#city option").remove();
		var parentKey = $("#province").val();
		if(parentKey == ""){
			$("#city").append("<option value=''>--------请选择--------</option>");
		}else{
			var obj = {"parentKey":parentKey};
			$.post("${ctx}/front/esp/espadmin-getcounty.action", obj, function(data){
				if(!!data){
					$("#city").attr("disabled",false);
					var json = eval('('+data+')');
					var dicIds = json.dicIds.split("@");
					var dicKeys = json.dicKeys.split("@");
					var dicValues = json.dicValues.split("@");
					var str = "";
					str+="<option value=''>--------请选择--------</option>";
					for(var i = 0 ; i < dicIds.length ; i++){
						str+="<option value='"+dicKeys[i]+"'>"+dicValues[i]+"</option>";
					}
					$("#city").append(str);
				}else{
					var option = $("#province").find("option:selected");
					var key = option.attr("value");
					var value = option.html();
					$("#city").append("<option value='"+key+"'>"+value+"</option>");
				}
			});
		}
	}
	$$.tab("#listoperate a",".listadd table","click");
	$(function(){
		$('body').click(function(){
			$(".area_alredy").children('div').hide(100);
		});
		$(".area_alredy").click(function(event){
			if ($(this).children('div').css('display')=="none"){
				$(this).children('div').stop().show(100);
			}else{
				$(".area_alredy").children('div').hide(100);
			}
			event.stopPropagation();
		});
		$(".area_alredy div").click(function(event){
			event.stopPropagation();
		});
		$(".area_alredy select").change(function(){
			var area_list="";
		    var Cts = "";     
			for (i=0;i<$(".area_alredy select").length;i++){
				Cts=$(".area_alredy select").eq(i).find("option:selected").text();
			    if(Cts.indexOf("请选择") < 0 ){    
			    	area_list+=Cts+" ";
			     }
			}
			$(".area_alredy span").html(area_list);
		})
	});
</script>